const mysql = require('mysql'),
    config = require('./../../config'),
    dbConfig = config.database,
    pool = mysql.createPool({
        host: dbConfig.HOST,
        user: dbConfig.USERNAME,
        password: dbConfig.PASSWORD,
        database: dbConfig.DATABASE
    });


let query = function (sql, values) {
    return new Promise((resolve, reject) => {
        pool.getConnection(function (err, connection) {
            if (err) {
                console.log(err);
                resolve(err);
            } else {
                connection.query(sql, values, (err, rows) => {
                    if (err) {
                        console.log(err);
                        reject(err);
                    } else {
                        resolve(rows)
                    }
                    connection.release();
                })
            }
        })
    })
};

module.exports = {
    query
};